import { FlatConfigComposer, type ResolvableFlatConfig } from 'eslint-flat-config-utils'
import { type ConfigNames, FlatConfig, Options } from '../types'
import { resolveOptions } from '../resolveOptions'
import gitignore from './gitignore'
import imports from './imports'
import javascript from './javascript'
import markdown from './markdown'
import n from './n'
import prettier from './prettier'
import typescript from './typescript'
import unicorn from './unicorn'
import vue from './vue'
import command from './command'

export const config = (
  options: Options = {},
  ...otherConfig: ResolvableFlatConfig<FlatConfig>[]
): FlatConfigComposer<FlatConfig, ConfigNames> => {
  const o = resolveOptions(options)
  const c = new FlatConfigComposer(
    gitignore(o.gitignore),
    javascript(o.javascript),
    n(o.n),
    imports(o.imports),
    unicorn(o.unicon)
  )

  if (o.typescript.enable) {
    c.append(typescript(o.typescript))
  }

  if (o.vue.enable) {
    c.append(vue(o))
  }

  c.append(markdown())

  if (o.command.enable) {
    c.append(command(o.command))
  }

  c.append(...otherConfig)

  if (o.prettier.enable) {
    c.append(prettier(o.prettier))
  }

  return c
}
